<template>
	<view>

		<!-- #ifndef MP -->
		<view class="page-foot">
			<view class="btn-logout" @tap="logout">退出登录</view>
		</view>
		<!-- #endif -->

		<view class="container">
			<view class="navbox">

				<view @tap="" class="flex-box flex-between nav" hover-class="none">
					<view class="flex-box">
						<!-- 	<image :src="item.icon" class="pnavs"></image> -->
						<view class="fs2">接收新消息通知</view>
					</view>
					<view class="icon_close-r-news">
						<u-switch v-model="is_news" v-if="!loading" size="32" asyncChange @change="asyncChange">
						</u-switch>
						<u-switch v-model="is_news" v-else loading size="32" asyncChange @change="asyncChange">
						</u-switch>
					</view>
				</view>
			</view>

			<block v-if="identify == 0">
				<view class="navbox">
					<template v-for="(item, index) in usernavs">
						<view @tap="jumpToPages" :data-jump_type="item.jump_type" :data-url="item.url"
							class="flex-box flex-between nav" hover-class="none">
							<view class="flex-box">
								<!-- 	<image :src="item.icon" class="pnavs"></image> -->
								<view class="fs2">{{ item.title }}</view>
							</view>
							<image src="/static/icon/icon_close-r.png" class="icon_close-r"></image>
						</view>
					</template>
				</view>
			</block>
			<block v-else>
				<view class="navbox">
					<template v-for="(item, index) in managernavs">
						<view @tap="jumpToPages" :data-jump_type="item.jump_type" :data-url="item.url"
							class="flex-box flex-between nav" hover-class="none">
							<view class="flex-box">
								<!-- <image :src="item.icon" class="pnavs"></image> -->
								<view class="fs32">{{ item.title }}</view>
							</view>
							<image src="/static/icon/icon_close-r.png" class="icon_close-r"></image>
						</view>
					</template>
				</view>
			</block>

			<view @tap="checkVersion" class="navbox" v-if="version">

				<view class="flex-box flex-between nav" hover-class="none">
					<view class="flex-box">
						<!-- 	<image :src="item.icon" class="pnavs"></image> -->
						<view class="fs2">当前版本</view>
					</view>
					<view class="icon_close-r-version">
						<text>{{version}}</text>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	const app = getApp();
	const functions = require('../../../utils/functions.js');
	export default {
		data() {
			return {
				info: null,
				identify: 0,
				version: '1.0.1',
				is_click: false,
				is_news: false,
				loading: false,
				//0用户，1咨询师
				// jump_type:1=不需要登录直接跳转，2=需要登录，登陆后跳转，3=拨打热线电话，4=下载App(?)
				usernavs: [
					// {icon:'/static/icon/icon_pnav9.png',title:'系统消息',jump_type:1,url:'/pages/chat/system_msg/system_msg'},
					{
						icon: '/static/static/icon/icon_pnav10.png',
						title: '帮助与反馈',
						jump_type: 2,
						url: '/pages/member/help_complain/help_complain'
					},

					{
						icon: '/static/static/icon/icon_pnav4.png',
						title: '关于佳和房产',
						jump_type: 1,
						url: '/pages/member/about/about'
					}, // {icon:'/static/icon/icon_pnav5.png',title:'下载APP',jump_type:4,url:''},
					{
						icon: '/static/static/icon/icon_pnav6.png',
						title: '隐私政策',
						jump_type: 1,
						url: '/pages/member/agreement/agreement?type=1'
					},
					{
						icon: '/static/static/icon/icon_pnav6.png',
						title: '用户协议',
						jump_type: 1,
						url: '/pages/member/agreement/agreement?type=2'
					}
				],
				managernavs: [{
						icon: '/static/static/icon/icon_pnav10.png',
						title: '帮助与反馈',
						jump_type: 2,
						url: '/pages/member/help_complain/help_complain'
					}, // {icon:'/static/icon/icon_pnav9.png',title:'系统消息',jump_type:1,url:'/pages/chat/system_msg/system_msg'},
					{
						icon: '/static/static/icon/icon_pnav4.png',
						title: '关于佳和房产',
						jump_type: 1,
						url: '/pages/member/about/about'
					},
					{
						icon: '/static/static/icon/icon_pnav6.png',
						title: '隐私协议',
						jump_type: 1,
						url: '/pages/member/agreement/agreement'
					}
				]
			};
		},
		onLoad: function(options) {
			this.initData();
			//     MP  代表5+App
			// #ifdef APP-PLUS
			//如果是小程序  例如显示返回按钮
			var that =this;
			plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
				var version = widgetInfo.version;
				console.log(version)
				that.version =version;
				functions.checkUpdate(false);
			})
		
			// #endIf  
		},

		methods: {

			asyncChange(e) {
				uni.showModal({
					content: e ? '确定要打开吗' : '确定要关闭吗',
					success: (res) => {
						this.loading = true;
						this.updateMsg_type()
					}
				})
			},
			bindAuthorizeToggle: function() {
				this.setData({
					authorizeStatus: false
				}); // 如果是个人中心，可以在这里初始化获取用户信息
			},

			// 跳转页面
			jumpToPages(event) {
				var that = this;
				var jump_type = Number(event.currentTarget.dataset.jump_type);
				var url = event.currentTarget.dataset.url;

				if (jump_type == 1) {
					uni.navigateTo({
						url: url
					});
				} else if (jump_type == 2) {
					app.globalData.nowThat = this;
					functions.checkLogin(function(ret) {
						if (ret) {
							uni.navigateTo({
								url: url
							});
						} else {
							functions.toast('请先登录');
						}
					});
				} else if (jump_type == 3) {
					var tel = app.globalData.config.platform_contact_tel;
					functions.phoneCall({
						phoneNumber: tel //仅为示例，并非真实的电话号码
					});
				}
			},
			logout: function() {
				uni.removeStorageSync('token');
				uni.removeStorageSync('mobile');
				functions.checkLogin();
			},
			initData() {
				var that = this;

				functions.getAjaxData('/api/xiluhouse.user/index', {}, function(res) {
					if (res.data.msg_open_state == 1) {
						that.is_news = true;
					} else {
						that.is_news = false;
					}
					that.info = res.data;

				});
			},
			updateMsg_type() {
				var that = this;

				functions.getAjaxData('/api/xiluhouse.user/msgOpenState', {}, function(res) {
					if (res.data.msg_open_state == 1) {
						that.is_news = true;
					} else {
						that.is_news = false;
					}
					uni.setStorageSync('msg_on_state',that.is_news?'msg_on':'msg_off');
					that.loading = false;
				});
			},
			checkVersion: function() {
				
				functions.checkUpdate(true);
				//functions.CheckUpdate(true);
				
			},
			

		}
	};
</script>

<style lang="scss" scoped>
	.container {
		background: #f6f7fa;
	}

	.page-foot {
		padding: 0 55rpx 40rpx;
	}

	.page-foot .btn-logout {
		width: 640rpx;
		height: 90rpx;
		background: #EEEEEE;
		border-radius: 10rpx;
		font-size: 30rpx;
		color: #898989;
		line-height: 90rpx;
		text-align: center;
	}

	.navbox {
		padding: 0 40rpx;
		background-color: #fff;
	}

	.navbox .nav {
		height: 115rpx;
		border-bottom: 1px solid #f5f5f5;
	}

	.navbox .nav:last-child {
		border-bottom: transparent;
	}

	.navbox .pnavs {
		display: block;
		width: 42rpx;
		height: 42rpx;
		margin-right: 14rpx;
		margin-left: 20rpx;
	}

	.navbox .icon_close-r {
		width: 25rpx;
		height: 25rpx;
	}

	.navbox .icon_close-r-news {
		width: 25rpx;
		height: 25rpx;
		margin-right: 25rpx;
	}

	.navbox .icon_close-r-version {
		width: 80rpx;
		height: 25rpx;
		margin-right: 25rpx;
	}
</style>
